import React, { Component } from 'react';

class User extends Component {
  constructor() {
    super();
    this.state = {
      val1: ''
    }
  }
  change() {
    // console.log(this.props.changeName);
    // console.log(this.state.val1);
    this.props.changeName(this.state.val1)
  }
  render() {
    return (
      <div>
        <p>User-子组件</p>
        <p>name: {this.props.name}</p>
        <p>age: {this.props.age}</p>
        <input value={this.state.val1} onChange={(e)=>this.setState({val1: e.target.value})}></input>
        <button onClick={()=>this.change()}>修改名字</button>
      </div>
    );
  }
}

export default User;
